package com.woniuxy.woniuticket.moviemodule.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.woniuticket.moviemodule.service.CinemaHallService;
import com.woniuxy.woniuticket.pojo.CinemaHall;
import com.woniuxy.woniuticket.resultcommon.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Utopia
 * @title: CinemaHallConroller
 * @projectName woniuticket
 * @description: TODO
 * @date 2019/6/10 19:48
 */

@Controller
@RequestMapping("/hall")
public class CinemaHallConroller {
    @Resource
    private CinemaHallService cinemaHallService;

    @RequestMapping("/selectAll")
    @ResponseBody
    public Object selectAllHall(@RequestParam(value = "page",defaultValue = "1",required = false) Integer currentPage, @RequestParam(value = "limit",defaultValue = "5",required = false) Integer pageSize){

        List<CinemaHall> list = cinemaHallService.selectAll(currentPage,pageSize);
        PageInfo pageInfo = new PageInfo(list);
        Map map = new HashMap();
        map.put("code", 0);
        map.put("message", "数据响应成功");
        map.put("count", pageInfo.getTotal());
        map.put("data", pageInfo.getList());
        return map;
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public Object selectById(Integer id){
        CinemaHall cinemaHall = cinemaHallService.selectById(id);
        return cinemaHall;
    }

    @RequestMapping("/add")
    @ResponseBody
    public JsonResult addCinemaHall(CinemaHall cinemaHall){
        int row = cinemaHallService.insertCinemaHall(cinemaHall);
        if (row>0){
            return JsonResult.ok("增加成功");
        }
        return JsonResult.error("增加失败");
    }

    @RequestMapping("/update")
    @ResponseBody
    public JsonResult updateCinemaHall(CinemaHall cinemaHall){
        int row = cinemaHallService.upadteCinemaHall(cinemaHall);
        if (row>0){
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult deleteCinemaHall(String ids){
        int row = cinemaHallService.deleteCinemaHall(ids);
        if (row>0){
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
